// router/index.js
import { createRouter, createWebHistory } from 'vue-router'
import HomeLayout from '@/views/home/IndexView.vue'
import Home from '@/views/home/HomeContent.vue'
import login from '@/views/login/IndexView.vue'
import usermanage from '@/views/usermanage/IndexView.vue'
import dashboard from '@/views/dashboard/IndexView.vue'
import operatedict from '@/views/operatedict/IndexView.vue'
import operatedictDetail from '@/views/operatedict/detail/IndexView.vue'
import stmsettings from '@/views/stmsettings/IndexView.vue'
import menuManagemnet from '@/views/MenuManagement/IndexView.vue'
import userinfo from '@/views/userinfo/IndexView.vue'
import filemanage from '@/views/filemanage/IndexView.vue'
import PageForbidden from '@/views/error/PageForbidden.vue'
import PageNotFound from '@/views/error/PageNotFound.vue'

import MessageCenter from '@/views/personal/MessageCenter.vue'
import { ProcessList, ProcessDesigner } from '@/views/workflow'


// 管理员专用路由组件（示例）
const AdminDashboard = {
  template: '<div><h2>管理员专属仪表板</h2><p>只有管理员才能看到这个页面</p></div>'
}

const routesData = [
  { path: '/menuManagemnet', name: '菜单管理', icon: 'fa fa-user', meta: { roles: ['admin'] } },
  { path: '/usermanage', name: '用户管理', icon: 'fa fa-user', meta: { roles: ['admin'] } },
  {
    path: '/dashboard',
    name: '资源看板',
    icon: 'fa fa-bar-chart',
    meta: { roles: ['admin', 'user'] },
  },
  { path: '/filemanage', name: '文件管理', icon: 'fa fa-file', meta: { roles: ['admin', 'user'] } },
  { path: '/operatedict', name: '操作日志', icon: 'fa fa-cogs', meta: { roles: ['admin'] } },
  { path: '/stmsettings', name: '系统设置', icon: 'fa fa-cog', meta: { roles: ['admin'] } },
  { path: '/userinfo', name: '个人信息', icon: 'fa fa-user-circle', meta: { roles: ['admin', 'user'] } },
  // 工作流路由
  { path: '/workflow/list', name: '流程管理', icon: 'fa fa-tasks', meta: { roles: ['admin'] } },
  { path: '/workflow/designer', name: '流程设计', icon: 'fa fa-edit', meta: { roles: ['admin'] } },
  // 个人页面路由
  { path: '/personal/messages', name: '消息中心', icon: 'fa fa-envelope', meta: { roles: ['admin', 'user'] } },

]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: HomeLayout, // 使用主布局组件
      props: { routes: routesData }, // 将路由数据传递给布局组件
      meta: { title: '首页' },
      children: [
        {
          path: '', // 空路径表示默认子路由
          name: 'home',
          component: Home, // 首页内容组件
          meta: { title: '首页' },
        },
        {
          path: '/menuManagemnet',
          name: '菜单管理',
          component: menuManagemnet,
          meta: { roles: ['admin'], title: '菜单管理' },
        },
        {
          path: '/usermanage',
          name: '用户管理',
          component: usermanage,
          meta: { roles: ['admin'], title: '用户管理' },
        },
        {
          path: '/dashboard',
          name: '资源看板',
          component: dashboard,
          meta: { roles: ['admin', 'user'], title: '资源看板' },
        },
        {
          path: '/operatedict',
          name: '操作日志',
          component: operatedict,
          meta: { roles: ['admin'], title: '操作日志' },
        },
        {
          path: '/operatedict/detail/:id',
          name: '操作日志详情',
          component: operatedictDetail,
          meta: { roles: ['admin'], title: '操作日志详情' },
        },
        {
          path: '/stmsettings',
          name: '系统设置',
          component: stmsettings,
          meta: { roles: ['admin'], title: '系统设置' },
        },
        {
          path: '/userinfo',
          name: '个人信息',
          component: userinfo,
          meta: { roles: ['admin', 'user'], title: '个人信息' },
        },
        // 管理员专用子路由示例
        {
          path: '/admin',
          name: '管理员专区',
          meta: { roles: ['admin'], title: '管理员专区' },
          children: [
            {
              path: 'dashboard',
              name: '管理员仪表板',
              component: AdminDashboard,
              meta: { roles: ['admin'], title: '管理员仪表板' }
            },
            {
              path: 'settings',
              name: '管理员设置',
              component: {
                template: '<div><h2>管理员设置</h2><p>管理员专用设置页面</p></div>'
              },
              meta: { roles: ['admin'], title: '管理员设置' }
            }
          ]
        },
        {
          path: '/filemanage',
          name: '文件管理',
          component: filemanage,
          meta: { roles: ['admin'], title: '文件管理' },
        },
        // 个人页面路由
        {
          path: '/personal/messages',
          name: '消息中心',
          component: MessageCenter,
          meta: { roles: ['admin', 'user'], title: '消息中心' },
        },

        // 工作流路由
        {
          path: '/workflow/list',
          name: '流程管理',
          component: ProcessList,
          meta: { roles: ['admin'], title: '流程管理' },
        },
        {
          path: '/workflow/designer',
          name: '流程设计',
          component: ProcessDesigner,
          meta: { roles: ['admin'], title: '流程设计' },
        },

        // 其他需要在布局中显示的路由
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: login, // 登录页不需要侧边栏，直接作为根路由
      meta: { title: '登录' },
    },
    {
      path: '/403',
      name: 'PageForbidden',
      component: PageForbidden,
      meta: { title: '无权限访问' },
    },
    // 404页面，必须放在最后
    {
      path: '/:pathMatch(.*)*',
      name: 'PageNotFound',
      component: PageNotFound,
      meta: { title: '页面未找到' },
    },
  ],
})

export default router
